2
2
.
.
4
4
.
.
3
3
@
@
P
P
o
o
s
s
t
t
M
M
a
a
p
p
p
p
i
i
n
n
g
g
I
I
n
n
f
f
o
o
[
[
G
G
]
]
@PostMapping Annotation tells Spring for which URL to call this Endpoint.
But Endpoint will be called only for HTTP POST Requests.
You can combine it with other Annotations of this type.
For instance if you also use @GetMapping on the same Endpoint, it will get called for both HTTP GET and POST Requests.
Application Schema [Results]
Spring Boot Starters
GROUP
DEPENDENCY
DESCRIPTION
Web
Spring Web
Enables: @Controller, @ResponseBody, @PostMapping, Tomcat Server
P
P
r
r
o
o
c
c
e
e
d
d
u
u
r
r
e
e
Create Project: controller_returns_text (add Spring Boot Starters from the table)
Create Package: controllers (inside main package)
Create Class: MyController.java (inside controllers package)
MyController.java
package com.ivoronline.springboot_endpoint_annotation_postmapping.controllers;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@ResponseBody
@PostMapping("/Hello")
public String hello() {
return "Hello from Controller";
}
}
hello()
MyController
http://localhost:8080/Hello
Browser